<template>
  <div style="height: 100vh; overflow: hidden; position: relative" class="bj">
    <div style="width: 500px; height: 400px;border-radius: 10px;
        margin: 150px auto; padding:50px">
      <div style="margin: 30px; text-align: center; font-size: 30px; font-weight: bold; color: dodgerblue">源小茶系统登录</div>
      <el-form :model="user" :rules="rules" ref="loginForm">
        <el-form-item prop="uname">
          <el-input placeholder="请输入账号" prefix-icon="el-icon-user" size="medium" v-model="user.uname"></el-input>
        </el-form-item>
        <el-form-item prop="upwd">
          <el-input placeholder="请输入密码" show-password prefix-icon="el-icon-lock" size="medium" v-model="user.upwd"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="width: 100%" size="medium" type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>

import request from "@/utils/request";

export default {
  name: 'LOGIN',
  data() {
    return {
      loginAdmin: {},
      user: {},
      rules: {
        uname: [
          { required: true, message: '请输入用户名', trigger: 'blur'},
          { min: 3, max: 10, message: '长度在3-10个字符', trigger: 'blur'}
        ],
        upwd: [
          { required: true, message: '请输入密码', trigger: 'blur'},
          { min: 3, max: 10, message: '长度在3-10个字符', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    login() {
      this.$refs['loginForm'].validate((valid) => {
        if (valid) {
          request.post('/user/login', this.user).then(res => {
            if (res.code === '200') {
              this.loginAdmin = res.data
              this.$router.push("/")
              this.$notify.success('登录成功')
            } else {
              this.$notify.error(res.msg)
            }
          })
        }
      })
    },
  }
}
</script>

<style>


.bj{
  background-image: url('@/assets/bj.webp');
}

</style>